(function($)
{
	$.fn.tabbutton = function(defaultValue, boundary, boundaryHtml)
	{
		this.attr('class', 'tabbutton');
		
		var liDoms = this.children('li');
		
		for (var index = 0; index < liDoms.length; index++)
		{
			var liDom = liDoms[index];
			
			if (defaultValue && $(liDom).attr('value') == defaultValue)
			{
				$(liDom).attr('class', 'selected');
			}
			else
			{
				$(liDom).attr('class', 'none-selected');
			}
			
			if (boundary && index > 0)
			{
				var boundaryDom = $('<li></li>');
				
				boundaryDom.attr('class', 'boundary');
				
				if (boundaryHtml)
				{
					boundaryDom.html(boundaryHtml);
				}
				
				boundaryDom.insertBefore($(liDom));
			}
			
			$(liDom).click({button : this}, function(e)
			{
				var target = e.currentTarget;
				
				if ($(target).attr('class') == 'selected')
				{
					return;
				}
				
				$(target.tagName).each(function()
				{
					if ($(this).attr('class') == 'boundary')
					{
						return;
					}
					
					$(this).attr('class', 'none-selected');	
				});
				
				$(target).attr('class', 'selected');
				
				$(e.data.button).val($(e.currentTarget).attr('value'));
				
				$(e.data.button).trigger('select');
			});
			
			$(liDom).mouseover(function(e)
			{
				var target = e.currentTarget;
				
				if ($(target).attr('class') == 'selected')
				{
					return;
				}
				
				$(target).attr('class', 'none-selected mouseover');
			});
			
			$(liDom).mouseout(function(e)
			{
				var target = e.currentTarget;
				
				if ($(target).attr('class') == 'selected')
				{
					return;
				}
				
				$(target).attr('class', 'none-selected');
			});
		}
	};
})(jQuery);